﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using Converter;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;
using System.Resources;
using System.Reflection;

namespace csla4Skeleton.UI.SL.Reports
{
    public partial class ReportDate : ChildWindow
    {
        private ReportType reportType;
        public ReportDate(ReportType mode)
        {
            this.reportType = mode;
            LocalizationConverter converter = new LocalizationConverter();
            converter.LocalResourceManager = new ResourceManager("csla4Skeleton.UI.SL.Reports.Resources", Assembly.GetExecutingAssembly());
            this.Resources.Add("Localization", converter);

            InitializeComponent();
        }

        #region properties
        public DateTime FromDate
        {
            set;
            get;
        }

        public DateTime ToDate
        {
            set;
            get;
        }
        #endregion

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            if ((FromDateTextBox.SelectedDate == null) || (ToDateTextBox.SelectedDate == null))
                return;
            FromDate = (DateTime)FromDateTextBox.SelectedDate;
            ToDate = (DateTime)ToDateTextBox.SelectedDate;

            if ((FromDate == null) ||
                (ToDate == null))
            {
                MessageBox.Show("Bạn chưa chọn ngày cần làm báo cáo \n Xin vui lòng nhập lại!.", "Cảnh báo", MessageBoxButton.OK);
            }
            else if (FromDate > ToDate)
            {
                MessageBox.Show("Ngày bắt đầu sau ngày kết thúc \n Xin vui lòng nhập lại!.", "Cảnh báo", MessageBoxButton.OK);
            }
            else
            {
                this.Close();
                if (reportType == ReportType.BalanceAccountingReport)
                {
                    BalanceAccountingReport balanceAccountingReport = new BalanceAccountingReport(FromDate, ToDate);
                    balanceAccountingReport.Closing += new EventHandler<System.ComponentModel.CancelEventArgs>(EventReport_Closed);
                    balanceAccountingReport.Show();
                }
                else if (reportType == ReportType.BalanceDetailGenerationReport)
                {
                    BalanceDetailGenerationReport balanceDetailGenerationReport = new BalanceDetailGenerationReport(FromDate, ToDate);
                    balanceDetailGenerationReport.Closing += new EventHandler<System.ComponentModel.CancelEventArgs>(EventReport_Closed);
                    balanceDetailGenerationReport.Show();
                }
                else if (reportType == ReportType.BalanceGenerationReport)
                {
                    BalanceGenerationReport balanceGenerationReport = new BalanceGenerationReport(FromDate, ToDate);
                    balanceGenerationReport.Closing += new EventHandler<System.ComponentModel.CancelEventArgs>(EventReport_Closed);
                    balanceGenerationReport.Show();
                }
                else if (reportType == ReportType.BusinessResultReport)
                {
                    BusinessResultReport businessResultReport = new BusinessResultReport(FromDate, ToDate);
                    businessResultReport.Closing += new EventHandler<System.ComponentModel.CancelEventArgs>(EventReport_Closed);
                    businessResultReport.Show();
                }
                else if (reportType == ReportType.CashFlowReport)
                {
                    CashFlowReport cashFlowReport = new CashFlowReport(FromDate, ToDate);
                    cashFlowReport.Closing += new EventHandler<System.ComponentModel.CancelEventArgs>(EventReport_Closed);
                    cashFlowReport.Show();
                }

            }
        }

        void EventReport_Closed(object sender, System.ComponentModel.CancelEventArgs e)
        {
            //StyleManager.ApplicationTheme = new Office_BlueTheme();
        }

        private void DatePicker_KeyUp(object sender, KeyEventArgs e)
        {
            ControlBehavior.DatePickerBehaviors.DatePicker_KeyUp(sender, e, null);
        }
    }
}

